package com.dao.profile.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.dao.profile.ProfileDao;
import com.entity.other.Academy;
import com.entity.other.City;
import com.entity.other.Domitory;
import com.entity.other.IndustryBranch;
import com.entity.other.PositionBranch;
import com.entity.other.University;
import com.entity.userInfo.BasicInfo;
import com.entity.userInfo.ContactInfo;
import com.entity.userInfo.JuniorInfo;
import com.entity.userInfo.PersonalInfo;
import com.entity.userInfo.PrimaryInfo;
import com.entity.userInfo.SeniorInfo;
import com.entity.userInfo.TechnicalSchoolInfo;
import com.entity.userInfo.UniversityInfo;
import com.entity.userInfo.WorkInfo;

@Repository("profileDao")
public class ProfileDaoImpl extends HibernateDaoSupport implements ProfileDao{
	
	Session sesstion=null;

	@SuppressWarnings("unchecked")
	public List<City> getCityByProvinceId(int provinceId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(City.class);
		c.add(Restrictions.eq("provinceId", provinceId));
	 return (List<City>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<University> getUniversityByProvinceId(int provinceId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(University.class);
		c.add(Restrictions.eq("provinceId", provinceId));
	 return (List<University>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<BasicInfo> getBasicInfoByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(BasicInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<BasicInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<JuniorInfo> getJuniorByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(JuniorInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<JuniorInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<PersonalInfo> getPersonalInfoByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(PersonalInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<PersonalInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<PrimaryInfo> getPrimaryInfoByUserId(int userId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(PrimaryInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<PrimaryInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<SeniorInfo> getSeniorByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(SeniorInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<SeniorInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<TechnicalSchoolInfo> getTechnicalSchoolInfoByUserId(int userId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(TechnicalSchoolInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<TechnicalSchoolInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<UniversityInfo> getUniversityByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(UniversityInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<UniversityInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<WorkInfo> getWorkInfoByUserId(int userId) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(WorkInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<WorkInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<ContactInfo> getContactInfoByUserId(int userId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(ContactInfo.class);
		c.add(Restrictions.eq("userId", userId));
	 return (List<ContactInfo>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<Domitory> getDomitoryByUniversityId(int unversityId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(Domitory.class);
		c.add(Restrictions.eq("universityId", unversityId));
	 return (List<Domitory>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<Academy> getAcademyByUniversityId(int university)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(Academy.class);
		c.add(Restrictions.eq("universityId", university));
	 return (List<Academy>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<IndustryBranch> getIndustryBranchByIndustryId(int industryId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(IndustryBranch.class);
		c.add(Restrictions.eq("industryId", industryId));
	 return (List<IndustryBranch>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<PositionBranch> getPositionBranchByPositionId(int positionId)
			throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(PositionBranch.class);
		c.add(Restrictions.eq("positionId", positionId));
	 return (List<PositionBranch>)c.list();
	}

}
